diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py
index 97045d2f49..e7016f68b4 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -915,9 +915,16 @@ class ExpressionWrapper(Expression):
         return [self.expression]
 
     def get_group_by_cols(self, alias=None):
-        expression = self.expression.copy()
-        expression.output_field = self.output_field
-        return expression.get_group_by_cols(alias=alias)
+        if not self.contains_aggregate:
+            if hasattr(self.expression, 'select_format'):
+                return [self.expression]
+            else:
+                return [self]
+        else:
+            cols = []
+            for source in self.get_source_expressions():
+                cols.extend(source.get_group_by_cols())
+            return cols
 
     def as_sql(self, compiler, connection):
         return compiler.compile(self.expression)
